﻿using GalaSoft.MvvmLight;
using System;
using System.Windows.Input;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using System.Linq;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using ASoft.Service;

namespace ASoft.WPF.ViewModel
{
    /// <summary>
    /// 系统设置
    /// </summary>
    public class PhoneViewModel : ViewModelBase
    {
        public PhoneViewModel()
        {
            if (IsInDesignMode)
            {
                this._PhonePortName = "COM1";
                this.PhonePortNameSource = new string[] { "COM1", "COM2" };
            }
            else
            {
                this._PhonePortName = RC.Current.RootData.PhonePortName;
                this.PhonePortNameSource = SerialPortService.GetPortNames();
                this._MsgEnable = RC.Current.RootData.MsgEnable;

                this._PhoneSerialOvertime = RC.Current.RootData.PhoneSerialOvertime;
                this._Phone1Enable = RC.Current.RootData.Phone1Enable;
                this._Phone1Number = RC.Current.RootData.Phone1Number;
                this._Phone2Enable = RC.Current.RootData.Phone2Enable;
                this._Phone2Number = RC.Current.RootData.Phone2Number;
                this._Phone3Enable = RC.Current.RootData.Phone3Enable;
                this._Phone3Number = RC.Current.RootData.Phone3Number;


            }
        }
        public string[] PhonePortNameSource { get; private set; }
        public ICommand SaveCommand
        {
            get
            {
                return new RelayCommand(
                    () =>
                    {
                        RC.Current.RootData.MsgEnable = this.MsgEnable;
                        RC.Current.RootData.PhonePortName = this.PhonePortName;
                        RC.Current.RootData.PhoneSerialOvertime = this.PhoneSerialOvertime;
                        RC.Current.RootData.Phone1Enable = this.Phone1Enable;
                        RC.Current.RootData.Phone1Number = this.Phone1Number;
                        RC.Current.RootData.Phone2Enable = this.Phone2Enable;
                        RC.Current.RootData.Phone2Number = this.Phone2Number;
                        RC.Current.RootData.Phone3Enable = this.Phone3Enable;
                        RC.Current.RootData.Phone3Number = this.Phone3Number;
                        RC.Current.SaveRootData();
                    },
                    () =>
                    {
                        if (IsInDesignMode)
                        {
                            return false;
                        }
                        //return RC.Current.RootData.客户代码 != 客户代码;
                        return true;
                    });
            }
        }


        private bool _MsgEnable = default(bool);

        public bool MsgEnable
        {
            get
            {
                return _MsgEnable;
            }
            set
            {
                if (_MsgEnable == value)
                {
                    return;
                }
                _MsgEnable = value;
                RaisePropertyChanged("MsgEnable");
            }
        }

        private string _PhonePortName = default(string);

        public string PhonePortName
        {
            get
            {
                return _PhonePortName;
            }
            set
            {
                if (_PhonePortName == value)
                {
                    return;
                }
                _PhonePortName = value;
                RaisePropertyChanged("PhonePortName");
            }
        }

        private int _PhoneSerialOvertime = default(int);

        public int PhoneSerialOvertime
        {
            get
            {
                return _PhoneSerialOvertime;
            }
            set
            {
                if (_PhoneSerialOvertime == value)
                {
                    return;
                }
                _PhoneSerialOvertime = value;
                RaisePropertyChanged("PhoneSerialOvertime");
            }
        }

        private bool _Phone1Enable = default(bool);

        public bool Phone1Enable
        {
            get
            {
                return _Phone1Enable;
            }
            set
            {
                if (_Phone1Enable == value)
                {
                    return;
                }
                _Phone1Enable = value;
                RaisePropertyChanged("Phone1Enable");
            }
        }

        private string _Phone1Number = default(string);

        public string Phone1Number
        {
            get
            {
                return _Phone1Number;
            }
            set
            {
                if (_Phone1Number == value)
                {
                    return;
                }
                _Phone1Number = value;
                RaisePropertyChanged("Phone1Number");
            }
        }

        private bool _Phone2Enable = default(bool);

        public bool Phone2Enable
        {
            get
            {
                return _Phone2Enable;
            }
            set
            {
                if (_Phone2Enable == value)
                {
                    return;
                }
                _Phone2Enable = value;
                RaisePropertyChanged("Phone2Enable");
            }
        }

        private string _Phone2Number = default(string);

        public string Phone2Number
        {
            get
            {
                return _Phone2Number;
            }
            set
            {
                if (_Phone2Number == value)
                {
                    return;
                }
                _Phone2Number = value;
                RaisePropertyChanged("Phone2Number");
            }
        }

        private bool _Phone3Enable = default(bool);

        public bool Phone3Enable
        {
            get
            {
                return _Phone3Enable;
            }
            set
            {
                if (_Phone3Enable == value)
                {
                    return;
                }
                _Phone3Enable = value;
                RaisePropertyChanged("Phone3Enable");
            }
        }

        private string _Phone3Number = default(string);

        public string Phone3Number
        {
            get
            {
                return _Phone3Number;
            }
            set
            {
                if (_Phone3Number == value)
                {
                    return;
                }
                _Phone3Number = value;
                RaisePropertyChanged("Phone3Number");
            }
        }
    }
}